package com.yunhe.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;

import com.yunhe.bean.ShoppingCarInfo;
import com.yunhe.inter.ShoppingCarInfoInter;
import com.yunhe.util.SqlSessionFactoryUtil;

/**
 * 用于处理从购物车点击购买后所生成的购买信息页面
 */
@WebServlet("/ShoppingAddressServlet")
public class ShoppingAddressServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public ShoppingAddressServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//传递购物车中的商品ID拼接的字符串
		String commodityIDS = request.getParameter("commodityIDS");
		//此处暂时不考虑选取商品购买的方法，所以直接查询数据库中的购物车表
		//建立数据库连接
		SqlSession sqlSession =SqlSessionFactoryUtil.openSqlSession();
		ShoppingCarInfoInter mapper = sqlSession.getMapper(ShoppingCarInfoInter.class);
		//查询购物车中的信息
		ArrayList<ShoppingCarInfo> list  =mapper.findShoppingInfos();
		//将list集合放入request中
		request.setAttribute("list", list);
		request.setAttribute("commodityIDS", commodityIDS);
		request.getRequestDispatcher("/address_2.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
